<template>
  <h1>轮播图添加</h1>
  <el-form :model="form" label-width="auto">
    <el-form-item label="图片地址" >
      <el-input v-model="form.img" />
    </el-form-item>
    <el-form-item label="图片提示">
      <el-input v-model="form.alt" />
    </el-form-item>
    <el-form-item label="图片连接">
      <el-input v-model="form.link"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">添加</el-button>
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { reactive  } from "vue";
import {admin_banner_add} from '../../../utils/api'
import { useRouter } from 'vue-router';
import {ElNotification}  from 'element-plus'
import "element-plus/es/components/notification/style/css"
const $router = useRouter();
const form = reactive({
  img: '',
  alt:"",
  link:""
})
// 添加轮播图数据
const onSubmit = () => {
  if(form.img!="" && form.alt!="" && form.link!=""){
    admin_banner_add(form).then((res: any) => {
  if (res.data.code === "200") {
    ElNotification({
        title:"提示",
        message: "添加成功",
        type: "success",
    })
    $router.push("/admin/getbanner")
  }
})
  }else{
    ElNotification({
        title:"提示",
        message: "添加失败",
        type: "warning",
    })
}
}
</script>

<style scoped>
.el-input{
    width: 300px;
}
</style>